﻿using System;

namespace YJKGridTopologyCal.Index.Sweepline
{
	public class SweepLineEvent : IComparable
	{
		public SweepLineEvent(double x, SweepLineEvent insertEvent, SweepLineInterval sweepInt)
		{
			this.xValue = x;
			this.insertEvent = insertEvent;
			if (insertEvent != null)
			{
				this.eventType = SweepLineEvents.Delete;
			}
			else
			{
				this.eventType = SweepLineEvents.Insert;
			}
			this.sweepInt = sweepInt;
		}

		public bool IsInsert
		{
			get
			{
				return this.insertEvent == null;
			}
		}

		public bool IsDelete
		{
			get
			{
				return this.insertEvent != null;
			}
		}

		public SweepLineEvent InsertEvent
		{
			get
			{
				return this.insertEvent;
			}
		}

		public int DeleteEventIndex { get; set; }

		public SweepLineInterval Interval
		{
			get
			{
				return this.sweepInt;
			}
		}

		public int CompareTo(object o)
		{
			SweepLineEvent sweepLineEvent = (SweepLineEvent)o;
			if (this.xValue < sweepLineEvent.xValue)
			{
				return -1;
			}
			if (this.xValue > sweepLineEvent.xValue)
			{
				return 1;
			}
			if (this.eventType < sweepLineEvent.eventType)
			{
				return -1;
			}
			if (this.eventType > sweepLineEvent.eventType)
			{
				return 1;
			}
			return 0;
		}

		private readonly double xValue;

		private readonly SweepLineEvents eventType;

		private readonly SweepLineEvent insertEvent;

		private readonly SweepLineInterval sweepInt;
	}
}
